package com.itcast.demo.configuration;

import lombok.Setter;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author sai
 * @version 1.0
 * @date 2021/8/17 15:43
 */
@Configuration
@ConfigurationProperties(prefix = "es")
public class ElasticsearchConfiguration {

    private static final String SCHEME = "http";

    /**
     * ES Server IP
     */
    @Setter
    private String host;

    /**
     * port
     */
    @Setter
    private Integer port;

    @Bean
    public RestHighLevelClient restHighLevelClient() {
        return new RestHighLevelClient(
                RestClient.builder(new HttpHost(host, port, SCHEME)));
    }

}